package com.yxinsur.imc.web.controller.business;

import com.yxinsur.imc.business.domain.ImcInvoice;
import com.yxinsur.imc.business.form.ImcInvoiceForm;
import com.yxinsur.imc.business.service.IImcInvoiceService;
import com.yxinsur.imc.common.annotation.Log;
import com.yxinsur.imc.common.core.controller.BaseController;
import com.yxinsur.imc.common.core.domain.AjaxResult;
import com.yxinsur.imc.common.core.page.TableDataInfo;
import com.yxinsur.imc.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 发票Controller
 *
 * @author imc
 * @date 2021-05-31
 */
@RestController
@RequestMapping("/business/invoice")
public class ImcInvoiceController extends BaseController {
    @Autowired
    private IImcInvoiceService imcInvoiceService;

    /**
     * 开发票
     *
     * @param imcInvoiceForm ImcInvoiceForm
     * @return 结果
     */
    @Log(title = "开发票", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ImcInvoiceForm imcInvoiceForm) {
        return toAjax(imcInvoiceService.insertImcInvoice(imcInvoiceForm));
    }

    /**
     * 查询发票列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ImcInvoiceForm imcInvoiceForm) {
        startPage();
        List<ImcInvoice> list = imcInvoiceService.selectImcInvoiceList(imcInvoiceForm);
        return getDataTable(list);
    }

    /**
     * 获取发票详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:invoice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(imcInvoiceService.selectImcInvoiceById(id));
    }

    /**
     * 修改发票
     */
    @Log(title = "发票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImcInvoice imcInvoice) {
        return toAjax(imcInvoiceService.updateImcInvoice(imcInvoice));
    }

    /**
     * 删除发票
     */
    @PreAuthorize("@ss.hasPermi('system:invoice:remove')")
    @Log(title = "发票", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(imcInvoiceService.deleteImcInvoiceByIds(ids));
    }
}
